const path = require('path');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const baseConfig = require('./webpack.base.js');
const BASE_API = '/dev-api';

const config = {
  mode: 'development',
  // devtool: false,
  devServer: {
    contentBase: './dist',
    hot: true,
    port: 8080,
    proxy: {
      [BASE_API]: {
        target: 'http://localhost:8081/dev-api',
        changeOrigin: true,
        pathRewrite: {
          ['^' + BASE_API]: ''
        }
      }
    }
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env.BASE_API': JSON.stringify(BASE_API)
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: path.resolve(__dirname, '..', 'public'),
          to: path.resolve(__dirname, '..', 'dist'),
          globOptions: {
            ignore: ['**/public/index.html']
          }
        }
      ]
    })
  ]
};

module.exports = merge([baseConfig, config]);
